package com.example.yangxu0703.thundermapclient.util;


import android.util.Log;


public class ProduceThread extends Thread {

    public byte[] buff;
    public static boolean startdecode = true;
    public boolean isupdate = false;
    public static  byte[] SendBuff;


    public void setByteSource(byte[] buff) {
        this.buff = buff;
        isupdate = true;
       // ProduceThread.this.notify();
        synchronized ( ProduceThread.this) {
            ProduceThread.this.notify();
        }
    }

    @Override
    public void run() {
        super.run();

        while (true) {
            if (isupdate) {
                Log.i("Produce","SetByteSuccess!");
                if (!startdecode) {
                    Log.i("Produce","Thread wait!-1");
                    synchronized ( ProduceThread.this){
                        try {
                            ProduceThread.this.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

                } else {
                    //发送byte[] 给消费者；
               /*if (buff.length != 0) {
                    long tem_start = System.currentTimeMillis();
                    Log.i("Thread", "" + tem_start);
                    Bitmap bitmap = BitmapFactory.decodeByteArray(buff, 0, buff.length);
                    long diff_time=System.currentTimeMillis()-tem_start;
                    Log.i("Thread", "" + diff_time);
                    callback.decodefinish(bitmap);
                    startdecode = false;
                }*/
                    Log.i("Produce","qDatahasSend");
                    try {
                        sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Log.i("Produce","dataSize"+buff.length);
                    if (buff.length==0){
                        return;
                    }

                    SendBuff=buff;
                    startdecode=false;//消费者可以去拿数据了！
                    //isupdate=false;
                    synchronized (ConsumerThread.class){
                        ConsumerThread.class.notify();
                    }
                }
            } else {
                Log.i("Produce","Thread wait!-2");
                synchronized (ProduceThread.this) {
                    try {
                        ProduceThread.this.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    }

}
